package com.qfmy.web.app.controller.listenBook;

import com.qfmy.common.result.Result;
import com.qfmy.model.entity.listenBook.PlayRecord;
import com.qfmy.model.vo.listenBook.PlayRecordVo;
import com.qfmy.web.app.service.listenBook.PlayRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.web.app.controller.listenBook
 * @date 2025/11/01
 * @description 播放历史
 */
@RestController
@RequestMapping("/app/platRecord")
public class PlayRecordController {

    /**
     * 注入service
     */
    @Autowired
    private PlayRecordService playRecordService;

    /**
     * 保存播放历史
     */
    @RequestMapping("/savePlayRecord")
    public Result savePlayRecord(@RequestBody PlayRecord playRecord) {
        playRecordService.savePlayRecord(playRecord);
        return Result.ok();
    }

    /**
     * 删除播放历史
     */
    @RequestMapping("/deletePlayRecord")
    public Result deletePlayRecord(@RequestParam Integer playRecordId) {
        playRecordService.deletePlayRecord(playRecordId);
        return Result.ok();
    }

    /**
     * 获取播放历史
     */
    @RequestMapping("/getPlayRecord")
    public Result<List<PlayRecordVo>> getPlayRecord() {
        List<PlayRecordVo> playRecordVos =  playRecordService.getPlayRecord();
        return Result.ok(playRecordVos);
    }

    /**
     * 根据音频id获取播放记录
     */
    @RequestMapping("/getPlayRecordByAudioId")
    public Result<PlayRecordVo> getPlayRecordByAudioId(@RequestParam Integer audioId) {
        PlayRecordVo playRecordVo = playRecordService.getPlayRecordByAudioId(audioId);
        return Result.ok(playRecordVo);
    }

    /**
     * 清除所有的播放历史
     */
    @RequestMapping("/clearAllPlayRecord")
    public Result clearAllPlayRecord() {
        playRecordService.clearAllPlayRecord();
        return Result.ok();
    }


}
